package android07.newtop.activity;

import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.animation.Animation;

import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.jude.beam.bijection.RequiresPresenter;
import com.jude.beam.expansion.data.BeamDataActivity;

import android07.newtop.R;
import android07.newtop.model.bean.LaunchBean;
import android07.newtop.presenter.LaunchActivityPresenter;
import android07.newtop.utils.GlideUtil;


/**
 * 启动页面
 * 主要功能
 * 打开展示显示版本，版权  图片动画
 * 需要联网才能打开
 *
 *
 * 该页面的逻辑
 * LaunchBeanModel获取数据 并且用LaunchBean 承载
 * ------>LaunchActivityPresenter调用LaunchBeanModel获取数据，并且填充到Activity
 * ------>Acticity 中的setData中获得数据 开始展示

 * <p>
 * Created by hy on 2016/7/7
 */
@RequiresPresenter(LaunchActivityPresenter.class)
public class LaunchActivity extends BeamDataActivity<LaunchActivityPresenter, LaunchBean> {

    //日志TAG
    private static final String TAG = LaunchActivity.class.getSimpleName();
    TextView splashcopyright, splashversionname, splashtext, splashappname;
    ImageView splashimage;
    TextView textView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        //TODO 还没完成
        setContentView(R.layout.activity_splash);

        this.splashcopyright = (TextView) findViewById(R.id.splash_copyright);
        this.splashversionname = (TextView) findViewById(R.id.splash_version_name);
        this.splashtext = (TextView) findViewById(R.id.splash_text);
        this.splashappname = (TextView) findViewById(R.id.splash_app_name);
        this.splashimage = (ImageView) findViewById(R.id.splash_image);
        ListView listView = new ListView(this);


        textView = new TextView(this);

    }


    /**
     * 在LaunchActivityPresenter中的onCreateView中 调用
     * getDataSubscriber().onNext(new LaunchBeanModel().getLaunchBean(view));
     * 将数据穿到这里
     *
     * @param data
     */
    @Override
    public void setData(LaunchBean data) {
        super.setData(data);
        splashcopyright.setText(data.getCopyright());
        splashversionname.setText(data.getVersionName());

        splashtext.setText(data.getHuanyingci());


        //一行代码 解决图片问题
        GlideUtil.setImageUrl(data.getBackgroundurl(), splashimage);

        splashimage.startAnimation(data.getDonghua());
        data.getDonghua().setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationStart(Animation animation) {

                Log.d(TAG, "onAnimationStart: ");
            }

            @Override
            public void onAnimationEnd(Animation animation) {
                //动画播放完毕，跳转到主页
                getPresenter().startMainActivity(LaunchActivity.this);
                Log.d(TAG, "onAnimationEnd: ");
            }

            @Override
            public void onAnimationRepeat(Animation animation) {

            }
        });
    }


    /**
     * splash页面一般不要反回键，禁止
     * 防止返回键
     *
     * @param keyCode
     * @param event
     * @return
     */
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }

}
